import axios from "axios";
import { message } from 'antd';
import history from './History';

axios.defaults.baseURL = '/admin';

axios.interceptors.response.use((res) => {
  return res.data;
}, function (error) {
  const statusCode = error.response.status;
  if (statusCode === 401 || statusCode === 403) {
    message.error('未授权的操作，请登陆后重试!');
    console.log('history is ', history);
    history.push('/login');
  } else {
    message.error('系统异常,请稍后重试!');
  }
  return Promise.reject(error);
});

export default axios;